package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.corona.Game;
import com.corona.game.util.TextureCache;
import com.corona.game.util.audio.AudioLoader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;

/* compiled from: PkmnMap.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/FossilMachinePowerUp.class */
public class FossilMachinePowerUp extends Action {
    int timer = 0;
    ArrayList<Tile> buildingTiles = new ArrayList<>();
    Music soundEffect;
    boolean outro;

    public FossilMachinePowerUp(boolean outro, Action nextAction) {
        super(new Object[0]);
        this.outro = outro;
        this.nextAction = nextAction;
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        for (Tile tile : game.map.tiles.values()) {
            if (tile.name.contains("building1") && !tile.name.contains("building1_machine") && !tile.name.equals("building1_pokecenter1_right")) {
                this.buildingTiles.add(tile);
            }
        }
        if (this.outro) {
            Iterator<Tile> it = this.buildingTiles.iterator();
            while (it.hasNext()) {
                Tile tile2 = it.next();
                tile2.sprite.setRegion(0, 0, (int) tile2.sprite.getHeight(), (int) tile2.sprite.getHeight());
            }
            game.mapBatch.setColor(new Color(0.8f, 0.8f, 0.8f, 1.0f));
            game.actionStack.remove(this);
            game.insertAction(this.nextAction);
            return;
        }
        game.loadedMusic.put("para1", AudioLoader.loadMusic("sounds/para1.ogg"));
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        Iterator<Tile> it = this.buildingTiles.iterator();
        while (it.hasNext()) {
            Tile tile = it.next();
            if (this.timer < 50) {
                if (this.timer % 16 == 0) {
                    tile.sprite.setRegion(0, 0, (int) tile.sprite.getHeight(), (int) tile.sprite.getHeight());
                    if (tile.overSprite != null) {
                        tile.overSprite.setRegion(0, 0, (int) tile.sprite.getHeight(), (int) tile.overSprite.getHeight());
                    }
                    game.mapBatch.setColor(new Color(0.8f, 0.8f, 0.8f, 1.0f));
                }
                if (this.timer % 16 == 13) {
                    game.insertAction(new PlayMusic("para1", 0.7f, true, null));
                    tile.sprite.setRegion((int) tile.sprite.getHeight(), 0, (int) tile.sprite.getHeight(), (int) tile.sprite.getHeight());
                    if (tile.overSprite != null) {
                        tile.overSprite.setRegion((int) tile.sprite.getHeight(), 0, (int) tile.sprite.getHeight(), (int) tile.overSprite.getHeight());
                    }
                    game.mapBatch.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
                }
            } else if (this.timer < 90) {
                if (this.timer % 4 == 0) {
                    tile.sprite.setRegion(0, 0, (int) tile.sprite.getHeight(), (int) tile.sprite.getHeight());
                    if (tile.overSprite != null) {
                        tile.overSprite.setRegion(0, 0, (int) tile.sprite.getHeight(), (int) tile.overSprite.getHeight());
                    }
                    game.mapBatch.setColor(new Color(0.8f, 0.8f, 0.8f, 1.0f));
                }
                if (this.timer % 4 == 2) {
                    tile.sprite.setRegion((int) tile.sprite.getHeight(), 0, (int) tile.sprite.getHeight(), (int) tile.sprite.getHeight());
                    if (tile.overSprite != null) {
                        tile.overSprite.setRegion((int) tile.sprite.getHeight(), 0, (int) tile.sprite.getHeight(), (int) tile.overSprite.getHeight());
                    }
                    game.mapBatch.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
                }
            }
        }
        if (this.timer >= 70) {
            game.actionStack.remove(this);
            game.insertAction(this.nextAction);
        }
        this.timer++;
    }

    /* compiled from: PkmnMap.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/FossilMachinePowerUp$LightFlicker.class */
    static class LightFlicker extends Action {
        int timer = 0;
        int phase = 0;
        ArrayList<Tile> buildingTiles = new ArrayList<>();

        public LightFlicker(Action nextAction) {
            super(new Object[0]);
            this.nextAction = nextAction;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            for (Tile tile : game.map.tiles.values()) {
                if (tile.name.contains("building1") && !tile.name.contains("building1_machine") && !tile.name.equals("building1_pokecenter1_right")) {
                    this.buildingTiles.add(tile);
                }
            }
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "map";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return Action.Layer.map_0;
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (this.phase == 0) {
                if (this.timer >= 24) {
                    this.phase++;
                    this.timer = 0;
                } else if (this.timer % 24 == 0) {
                    Iterator<Tile> it = this.buildingTiles.iterator();
                    while (it.hasNext()) {
                        Tile tile = it.next();
                        tile.sprite.setRegion(0, 0, (int) tile.sprite.getHeight(), (int) tile.sprite.getHeight());
                        if (tile.overSprite != null) {
                            tile.overSprite.setRegion(0, 0, (int) tile.sprite.getHeight(), (int) tile.overSprite.getHeight());
                        }
                    }
                    game.mapBatch.setColor(new Color(0.8f, 0.8f, 0.8f, 1.0f));
                } else if (this.timer % 24 == 12) {
                    Iterator<Tile> it2 = this.buildingTiles.iterator();
                    while (it2.hasNext()) {
                        Tile tile2 = it2.next();
                        tile2.sprite.setRegion((int) tile2.sprite.getHeight(), 0, (int) tile2.sprite.getHeight(), (int) tile2.sprite.getHeight());
                        if (tile2.overSprite != null) {
                            tile2.overSprite.setRegion((int) tile2.sprite.getHeight(), 0, (int) tile2.sprite.getHeight(), (int) tile2.overSprite.getHeight());
                        }
                    }
                    game.mapBatch.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
                }
            }
            if (this.phase == 1) {
                if (this.timer >= 40) {
                    this.phase++;
                    this.timer = 0;
                } else if (this.timer % 40 == 0) {
                    Iterator<Tile> it3 = this.buildingTiles.iterator();
                    while (it3.hasNext()) {
                        Tile tile3 = it3.next();
                        tile3.sprite.setRegion(0, 0, (int) tile3.sprite.getHeight(), (int) tile3.sprite.getHeight());
                        if (tile3.overSprite != null) {
                            tile3.overSprite.setRegion(0, 0, (int) tile3.sprite.getHeight(), (int) tile3.overSprite.getHeight());
                        }
                    }
                    game.mapBatch.setColor(new Color(0.8f, 0.8f, 0.8f, 1.0f));
                } else if (this.timer % 40 == 20) {
                    Iterator<Tile> it4 = this.buildingTiles.iterator();
                    while (it4.hasNext()) {
                        Tile tile4 = it4.next();
                        tile4.sprite.setRegion((int) tile4.sprite.getHeight(), 0, (int) tile4.sprite.getHeight(), (int) tile4.sprite.getHeight());
                        if (tile4.overSprite != null) {
                            tile4.overSprite.setRegion((int) tile4.sprite.getHeight(), 0, (int) tile4.sprite.getHeight(), (int) tile4.overSprite.getHeight());
                        }
                    }
                    game.mapBatch.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
                }
            }
            if (this.phase == 2) {
                if (this.timer >= 48) {
                    this.phase++;
                    this.timer = 0;
                } else if (this.timer % 48 == 0) {
                    Iterator<Tile> it5 = this.buildingTiles.iterator();
                    while (it5.hasNext()) {
                        Tile tile5 = it5.next();
                        tile5.sprite.setRegion(0, 0, (int) tile5.sprite.getHeight(), (int) tile5.sprite.getHeight());
                        if (tile5.overSprite != null) {
                            tile5.overSprite.setRegion(0, 0, (int) tile5.sprite.getHeight(), (int) tile5.overSprite.getHeight());
                        }
                    }
                    game.mapBatch.setColor(new Color(0.8f, 0.8f, 0.8f, 1.0f));
                } else if (this.timer % 48 == 24) {
                    Iterator<Tile> it6 = this.buildingTiles.iterator();
                    while (it6.hasNext()) {
                        Tile tile6 = it6.next();
                        tile6.sprite.setRegion((int) tile6.sprite.getHeight(), 0, (int) tile6.sprite.getHeight(), (int) tile6.sprite.getHeight());
                        if (tile6.overSprite != null) {
                            tile6.overSprite.setRegion((int) tile6.sprite.getHeight(), 0, (int) tile6.sprite.getHeight(), (int) tile6.overSprite.getHeight());
                        }
                    }
                    game.mapBatch.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
                }
            }
            if (this.phase == 3) {
                if (this.timer >= 48) {
                    this.phase++;
                    this.timer = 0;
                } else if (this.timer % 48 == 0) {
                    Iterator<Tile> it7 = this.buildingTiles.iterator();
                    while (it7.hasNext()) {
                        Tile tile7 = it7.next();
                        tile7.sprite.setRegion(0, 0, (int) tile7.sprite.getHeight(), (int) tile7.sprite.getHeight());
                        if (tile7.overSprite != null) {
                            tile7.overSprite.setRegion(0, 0, (int) tile7.sprite.getHeight(), (int) tile7.overSprite.getHeight());
                        }
                    }
                    game.mapBatch.setColor(new Color(0.8f, 0.8f, 0.8f, 1.0f));
                } else if (this.timer % 48 == 24) {
                    Iterator<Tile> it8 = this.buildingTiles.iterator();
                    while (it8.hasNext()) {
                        Tile tile8 = it8.next();
                        tile8.sprite.setRegion((int) tile8.sprite.getHeight(), 0, (int) tile8.sprite.getHeight(), (int) tile8.sprite.getHeight());
                        if (tile8.overSprite != null) {
                            tile8.overSprite.setRegion((int) tile8.sprite.getHeight(), 0, (int) tile8.sprite.getHeight(), (int) tile8.overSprite.getHeight());
                        }
                    }
                    game.mapBatch.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
                }
            }
            if (this.phase == 4) {
                if (this.timer >= 56) {
                    this.phase++;
                    this.timer = 0;
                } else if (this.timer % 56 == 0) {
                    Iterator<Tile> it9 = this.buildingTiles.iterator();
                    while (it9.hasNext()) {
                        Tile tile9 = it9.next();
                        tile9.sprite.setRegion(0, 0, (int) tile9.sprite.getHeight(), (int) tile9.sprite.getHeight());
                        if (tile9.overSprite != null) {
                            tile9.overSprite.setRegion(0, 0, (int) tile9.sprite.getHeight(), (int) tile9.overSprite.getHeight());
                        }
                    }
                    game.mapBatch.setColor(new Color(0.8f, 0.8f, 0.8f, 1.0f));
                } else if (this.timer % 56 == 28) {
                    Iterator<Tile> it10 = this.buildingTiles.iterator();
                    while (it10.hasNext()) {
                        Tile tile10 = it10.next();
                        tile10.sprite.setRegion((int) tile10.sprite.getHeight(), 0, (int) tile10.sprite.getHeight(), (int) tile10.sprite.getHeight());
                        if (tile10.overSprite != null) {
                            tile10.overSprite.setRegion((int) tile10.sprite.getHeight(), 0, (int) tile10.sprite.getHeight(), (int) tile10.overSprite.getHeight());
                        }
                    }
                    game.mapBatch.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
                }
            }
            if (this.phase == 5) {
                game.actionStack.remove(this);
                game.insertAction(this.nextAction);
            }
            this.timer++;
        }
    }

    /* compiled from: PkmnMap.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/FossilMachinePowerUp$DoRevive.class */
    static class DoRevive extends Action {
        Tile machineTile;
        String pokemonName;
        Music soundEffect;
        int regionOffsetY;
        int timer = 0;
        int phase = 0;
        int offsetY = 0;
        Sprite fossilSprite = new Sprite(TextureCache.get(Gdx.files.internal("tiles/fossil1.png")), 0, 0, 16, 16);

        public DoRevive(String pokemonName, Action nextAction) {
            super(new Object[0]);
            this.regionOffsetY = 0;
            this.pokemonName = pokemonName;
            this.nextAction = nextAction;
            if (pokemonName.equals("OMANYTE")) {
                this.regionOffsetY = 16;
            } else if (pokemonName.equals("KABUTO")) {
                this.regionOffsetY = 32;
            } else if (pokemonName.equals("AERODACTYL")) {
                this.regionOffsetY = 0;
            } else if (pokemonName.equals("LILEEP")) {
                this.regionOffsetY = 48;
            } else if (pokemonName.equals("ANORITH")) {
                this.regionOffsetY = 64;
            } else if (pokemonName.equals("SHIELDON")) {
                this.regionOffsetY = 80;
            } else if (pokemonName.equals("CRANIDOS")) {
                this.regionOffsetY = 96;
            }
            this.fossilSprite.setRegion(0, this.regionOffsetY, 16, 16);
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            Iterator<Tile> it = game.map.tiles.values().iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                Tile tile = it.next();
                if (tile.name.equals("building1_pokecenter1")) {
                    this.machineTile = tile;
                    break;
                }
            }
            this.soundEffect = AudioLoader.loadMusic("sounds/machine1.ogg");
            this.soundEffect.setLooping(true);
            this.soundEffect.setVolume(0.7f);
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "map";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return Action.Layer.map_0;
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (this.phase == 0) {
                if (this.timer == 120) {
                    this.phase++;
                    this.timer = 0;
                }
            } else if (this.phase == 1) {
                if (this.timer == 1) {
                    this.soundEffect.play();
                }
                if (this.timer < 362) {
                    if (this.timer % 4 == 0) {
                        game.cam.translate(0.0f, 2.0f);
                        game.player.position.add(0.0f, 2.0f);
                        if (game.player.hmPokemon != null) {
                            game.player.hmPokemon.position.add(0.0f, 2.0f);
                        }
                    } else if (this.timer % 4 == 1) {
                        this.offsetY = 0;
                    } else if (this.timer % 4 == 2) {
                        game.cam.translate(0.0f, -2.0f);
                        game.player.position.add(0.0f, -2.0f);
                        if (game.player.hmPokemon != null) {
                            game.player.hmPokemon.position.add(0.0f, -2.0f);
                        }
                    } else if (this.timer % 4 == 3) {
                        this.offsetY = -2;
                    }
                    if (this.timer % 8 == 0) {
                        this.fossilSprite.setRegion(0, this.regionOffsetY, 16, 16);
                    } else if (this.timer % 8 == 4) {
                        this.fossilSprite.setRegion(16, this.regionOffsetY, 16, 16);
                    }
                    if (this.timer % 16 == 0) {
                        game.insertAction(new PlayMusic("teleport1", 0.5f, true, null));
                    }
                } else {
                    this.soundEffect.stop();
                    this.soundEffect.dispose();
                    this.machineTile.nameUpper = "revived_" + this.pokemonName;
                    game.actionStack.remove(this);
                    game.insertAction(this.nextAction);
                    game.insertAction(new WaitFrames(game, 90, new PokemonFrame(new Pokemon(this.pokemonName.toLowerCase(Locale.ROOT), 2, Pokemon.Generation.CRYSTAL, false, false), new WaitFrames(game, 20, new SplitAction(new LightFlicker(null), new PlayMusic("heal1_downshift", new SplitAction(new PlayMusic("stomp1", (Action) null), new FossilMachinePowerUp(true, new SetField(game, "playerCanMove", true, new SetField(game.player, "isCrafting", false, new SetField(game.player.hmPokemon, "dirFacing", "left", null)))))))))));
                }
            }
            game.mapBatch.draw(this.fossilSprite, this.machineTile.position.x + 8.0f, this.machineTile.position.y + 8.0f + ((float) this.offsetY));
            this.timer++;
        }
    }
}
